package com.pl.controller;

import com.pl.common.JsonResult;
import com.pl.domain.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author shent
 */
@RestController
@RequestMapping("/jsonResult")
public class JsonResultController {

    @GetMapping("user")
    public JsonResult<User> getUser() {
        User user = new User(1L, "测试用户1", "123456");
        return new JsonResult<>(user);
    }

    @GetMapping("/list")
    public JsonResult<List<User>> getUserList() {
        List<User> userList = new ArrayList<>();
        User user1 = new User(1L, "测试用户1", "123456");
        User user2 = new User(2L, "测试用户2", "123456");
        userList.add(user1);
        userList.add(user2);
        return new JsonResult<>(userList, "获取用户列表成功");
    }

    @GetMapping("/map")
    public JsonResult<Map<String, Object>> getMap() {
        Map<String, Object> map = new HashMap<>(3);
        User user = new User(1L, "测试用户1", null);
        map.put("作者信息", user);
        map.put("博客地址", "http://www.baidu.com");
        map.put("CSDN地址", null);
        map.put("粉丝数量", 2000);
        return new JsonResult<>(map);
    }


}
